package com.jt.controller;

import com.jt.pojo.User;
import com.jt.service.UserService;
import com.jt.vo.PageResult;
import com.jt.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 刘昱江
 * 时间 2021/5/11
 */
@RestController
@CrossOrigin
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("/hello")
    public List<User> hello(){

        return userService.findAll();
    }
    @PostMapping("/login")
    public SysResult login(@RequestBody User user){
        String token = userService.login(user);

        if(token == null){
            return SysResult.fail();
        }
        return SysResult.succeed(token);
    }
    @GetMapping("/list")
    public SysResult userList(PageResult pageResult){
        PageResult pageResult1 = userService.userList(pageResult);
        return SysResult.succeed(pageResult1);

    }
    @PostMapping("/addUser")
    public SysResult addUser(@RequestBody User user){
        userService.addUser(user);
        return SysResult.succeed();
    }


}
